package com.tomtop.core.dorequest;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import com.tomtop.core.utils.JSONUtils;

@Component
@ConfigurationProperties(prefix="tomtop")
public class HttpParamConfig implements InitializingBean {
	private static final Logger LOGGER = LoggerFactory .getLogger(HttpParamConfig.class);
	private static Map<String,HostName> dohttp;
	public static HostName getByName(String name) {
		HostName hostName= dohttp.get(name);
		if(hostName==null)
			LOGGER.error("{}主机配置参数不存在，请检查配置文件application.yml中tomtop.dohttp下的配置",name);
		return hostName;
	} 
	public Map<String, HostName> getDohttp() {
		return dohttp;
	}
	public void setDohttp(Map<String, HostName> dohttp) {
		HttpParamConfig.dohttp = dohttp;
	}

	

	@Override
	public void afterPropertiesSet() throws Exception {
		if(dohttp==null)
			dohttp=new HashMap<>();
		LOGGER.info("主机api配置的参数:{}",JSONUtils.toJSONString(dohttp));
	}
}
